package com.itboye.ihomebank.responsitory;

import com.google.gson.reflect.TypeToken;
import com.itboye.ihomebank.base.BaseNetRepository;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.CurrentDaiKuanBean;
import com.itboye.ihomebank.bean.FinancialXiangQingBean;
import com.itboye.ihomebank.bean.HaveInBean;
import com.itboye.ihomebank.bean.HuanKuanJiHuaBean;
import com.itboye.ihomebank.bean.HuanKuansBean;
import com.itboye.ihomebank.bean.JinRongBean;
import com.itboye.ihomebank.bean.P2PQueryBean;
import com.itboye.ihomebank.bean.PayInfo;
import com.itboye.ihomebank.bean.TouZiJiLuBean;
import com.itboye.ihomebank.bean.TouZiXQBean;
import com.itboye.ihomebank.bean.ZhuJiaBaoShouYeBean;
import com.itboye.ihomebank.interfaces.IJinRong;
import com.itboye.ihomebank.net.BaseErrorListener;
import com.itboye.ihomebank.net.BaseSuccessReqListener;
import com.itboye.ihomebank.net.ByJsonRequest;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/***
 * 请求网络类
 *
 * @author admin
 */
public class JinRongRepository extends BaseNetRepository implements
        IJinRong<JinRongBean> {
    String api = "100";
    String loginTypeKey = "BY_User_login";// 用户登录
    String p2pList = "BY_P2p_query";//BY_P2p列表
    String p2pDetail = "BY_P2p_item";//BY_P2p详情
    String jinrongIndex = "BY_P2p_item";//金融
    String myTouZi = "BY_P2p_myInvest";//我的投资
    String goumai = "BY_P2p_invest";//投资购买
    String zjbSy = "BY_Financial_index";//住家宝首页
    String touzi_jilu = "BY_P2p_lender";//投资记录
    String HuanKuanJiHua = "BY_P2p_payBackDue";//还款计划

    String Zhuanru = "BY_Financial_buy";//租金宝(活期)转入
    String Zhuanchu = "BY_Financial_takeout";//租金宝(活期)转出
    String financial_xiangqing = "BY_Financial_item";//租金宝(活期)详情
    private String currentJieKuan = "BY_Loan_current";//当前贷款
    private String jiekuanHistory = "BY_Loan_history";//借款历史
    private String huanKuanDetail = "BY_Loan_plan";//还款详情
    private String sendJinRongPay = "BY_Pay_payInfo";

    private String huikuan = "BY_P2p_payBackUser";//回款计划

    private String zhuangrang = "BY_P2p_transfer";//发布转让

    private String tongxunlu = "BY_Loan_address";//设置通讯录

    public JinRongRepository(ICompleteListener iCompleteListener) {
        super(iCompleteListener);
    }

    /**
     * 17.1 p2p列表
     *
     * @param current_page 页码
     * @param per_page     页码大小
     * @param b_status     0：起草中 1:募集中	2：募集完成  3：计息中	4：项目完成	5：项目挂起	13：1+2,查询用
     * @param dt_type      6386:散标投资		6387：优选计划
     * @param order        排序,0=>默认(时间大小),1=>年化大小,2=>年化小大,3=>周期大小,4=>周期小大
     */
    @Override
    public void listP2p(String current_page, String per_page, String b_status, String dt_type, String order) {
        Type type = new TypeToken<P2PQueryBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("current_page", current_page);
        map.put("per_page", per_page);
        map.put("b_status", b_status);
        map.put("dt_type", dt_type);
        map.put("order", order);
        (new ByJsonRequest.Builder<P2PQueryBean>())
                .setTypeVerParamsAndReturnClass(p2pList, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<P2PQueryBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void listP2p02(String current_page, String per_page, String b_status, String dt_type, String order) {
        Type type = new TypeToken<P2PQueryBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("current_page", current_page);
        map.put("per_page", per_page);
        map.put("b_status", b_status);
        map.put("dt_type", dt_type);
        map.put("order", order);
        (new ByJsonRequest.Builder<P2PQueryBean>())
                .setTypeVerParamsAndReturnClass(p2pList, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<P2PQueryBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void detailP2p(String id) {
        Type type = new TypeToken<TouZiXQBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        (new ByJsonRequest.Builder<TouZiXQBean>())
                .setTypeVerParamsAndReturnClass(p2pDetail, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<TouZiXQBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void indexJinRong(String uid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(jinrongIndex, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 我的投资
     *
     * @param uid
     * @param current_page
     * @param per_page
     * @param status
     */
    @Override
    public void onMyTouZhi(String uid, String current_page, String per_page, String status) {
        Type type = new TypeToken<HaveInBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("current_page", current_page);
        map.put("per_page", per_page);
        map.put("status", status);
        (new ByJsonRequest.Builder<HaveInBean>())
                .setTypeVerParamsAndReturnClass(myTouZi, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<HaveInBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 投资购买
     *
     * @param uid
     * @param id
     * @param money
     */
    @Override
    public void myGoumai(String uid, String id, String money) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("id", id);
        map.put("money", money);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(goumai, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 住家宝首页
     *
     * @param size
     */
    @Override
    public void zjbShouYe(String size) {
        Type type = new TypeToken<ZhuJiaBaoShouYeBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("size", size);
        (new ByJsonRequest.Builder<ZhuJiaBaoShouYeBean>())
                .setTypeVerParamsAndReturnClass(zjbSy, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<ZhuJiaBaoShouYeBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 投资记录
     *
     * @param id
     */
    @Override
    public void touZiJiLu(String id) {
        Type type = new TypeToken<TouZiJiLuBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        (new ByJsonRequest.Builder<TouZiJiLuBean>())
                .setTypeVerParamsAndReturnClass(touzi_jilu, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<TouZiJiLuBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onBenJinLiXi(String rate_year, String money, String month,String day, String pay_type, String start_time) {
        Type type = new TypeToken<HuanKuanJiHuaBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rate_year", rate_year);
        map.put("money", money);
        map.put("month", month);
        map.put("day", day);
        map.put("pay_type", pay_type);
        map.put("start_time", start_time);
        (new ByJsonRequest.Builder<HuanKuanJiHuaBean>())
                .setTypeVerParamsAndReturnClass(HuanKuanJiHua, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<HuanKuanJiHuaBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void onHuiKuan(String uid, String id) {
        Type type = new TypeToken<HuanKuanJiHuaBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("id", id);
        (new ByJsonRequest.Builder<HuanKuanJiHuaBean>())
                .setTypeVerParamsAndReturnClass(huikuan, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<HuanKuanJiHuaBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 租金宝购买转入
     *
     * @param uid
     * @param id
     * @param money
     */
    @Override
    public void onZhuanRu(String uid, String id, String money) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("id", id);
        map.put("money", money);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(Zhuanru, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 租金宝购买转出
     *
     * @param uid
     * @param id
     * @param money
     */
    @Override
    public void onZhuanChu(String uid, String id, String money) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("id", id);
        map.put("money", money);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(Zhuanchu, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 租金宝详情
     *
     * @param uid
     * @param id
     */
    @Override
    public void onXiangQing(String id, String uid) {
        Type type = new TypeToken<FinancialXiangQingBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        map.put("uid", uid);
        (new ByJsonRequest.Builder<FinancialXiangQingBean>())
                .setTypeVerParamsAndReturnClass(financial_xiangqing, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<FinancialXiangQingBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void currentJieKuan(String uid) {
        Type type = new TypeToken<CurrentDaiKuanBean.HuanKUanDetailBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        (new ByJsonRequest.Builder<CurrentDaiKuanBean.HuanKUanDetailBean>())
                .setTypeVerParamsAndReturnClass(currentJieKuan, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<CurrentDaiKuanBean.HuanKUanDetailBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void jiekuanHistory(String uid, String current_page, String per_page) {
        Type type = new TypeToken<CurrentDaiKuanBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("current_page", current_page);
        map.put("per_page", per_page);
        (new ByJsonRequest.Builder<ArrayList<CurrentDaiKuanBean>>())
                .setTypeVerParamsAndReturnClass(jiekuanHistory, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<ArrayList<CurrentDaiKuanBean>>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void huanKuanDetail(String uid, String id) {
        Type type = new TypeToken<HuanKuansBean>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("id", id);
        (new ByJsonRequest.Builder<HuanKuansBean>())
                .setTypeVerParamsAndReturnClass(huanKuanDetail, "101", map, type)
                .requestListener(
                        new BaseSuccessReqListener<HuanKuansBean>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void sendJinRongPay(String uid, String pay_code_type, int items, String pay_type, String wallet_pay_money, String wallet_only, String amount) {
        Type type = new TypeToken<PayInfo>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("pay_code_type", pay_code_type);
        map.put("items", items);
        map.put("pay_type", pay_type);
        map.put("wallet_pay_money", wallet_pay_money);
        map.put("wallet_only", wallet_only);
        map.put("amount", amount);

        (new ByJsonRequest.Builder<PayInfo>())
                .setTypeVerParamsAndReturnClass(sendJinRongPay, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<PayInfo>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    /**
     * 发布转让
     * @param id
     * @param uid
     */
    @Override
    public void fabuZhuangRang(String id, String uid) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("id", id);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(zhuangrang, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void tongXunLu(String uid, String address) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("uid", uid);
        map.put("address", address);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(tongxunlu, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }
}
